package Verification;

import java.util.ArrayList;

public class Main {

	/**
	 * Correctness settings.
	 */
	private final static int NUMBER_OF_CASES = 7;
	private final static boolean CORRECTNESS_ON = false;

	/**
	 * Benchmark settings.
	 */
	private final static boolean FIND_ALL = false;
	private final static int START = 200;
	private final static int STOP = 2000;
	private final static int INCREMENT = 10;
	private final static int RUNS_PER_INCREMENT = 8;

	public static void main(String[] args) throws Exception {

		System.out.println(String.valueOf(Runtime.getRuntime().maxMemory()/(1024*1024)));

		// Create logger
		Logger logger = new Logger();

		if(CORRECTNESS_ON) {
			CaseBased c = new CaseBased();
			c.run(NUMBER_OF_CASES, true);
		}

		// Run tests from START to STOP
		for(int i = START; i <= STOP; i += INCREMENT) {

			// Call garbage collector
			Runtime.getRuntime().gc();

			double averageTime = 0;
			double averageMemory = 0;
			long averageOccurrences = 0;

			// Pattern
			String[] pattern = { "p", "a", "t", "t", "e", "r", "n" };

			// Long word from Shakespeare
			//String[] pattern = {"h", "o", "n", "o", "r", "i", "f", "i", "c", "a", "b", "i", "l", "i", "t", "u", "d", "i", "n", "i", "t", "a", "t", "i", "b", "u", "s"};

			// Alphabet
			String[] alpha = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };

			// Make a certain amount of runs - used for averaging
			for(int j = 0; j < RUNS_PER_INCREMENT; j++) {

				Benchmark stress = new Benchmark();

				stress.run(i, 0.2, alpha, pattern, FIND_ALL);

				// Get measurements
				averageTime += stress.getTime();
				averageOccurrences += stress.getNumberOfOccurrences();
				averageMemory += stress.getMemory();

				stress = null;

				// Call garbage collector
				Runtime.getRuntime().gc();
			}

			// Calculate average
			averageTime /= RUNS_PER_INCREMENT;
			averageOccurrences /= RUNS_PER_INCREMENT;
			averageMemory /= RUNS_PER_INCREMENT;

			// Log the test
			logger.writeln(Logger.AVERAGE_TIME, String.valueOf(averageTime));
			logger.writeln(Logger.AVERAGE_OCCURRENCES, String.valueOf(averageOccurrences));
			logger.writeln(Logger.AVERAGE_MEMORY, String.valueOf(averageMemory));
			logger.writeln(Logger.DIMENSION, String.valueOf(i));

			// Printout on the console
			System.out.println(Integer.valueOf(i) + " " + Double.toString(averageTime));
			/*System.out.println( "\nStress test..." +
					"\n   Dimension [nodes]: " + Integer.valueOf(i) +
					"\n   Average occurrence: " + Long.toString(averageOccurrences) +
					"\n   Average run time [ms]: " + Double.toString(averageTime) +
					"\n   Average memory usage [Kb]: " + Double.toString(averageMemory));
			*/
		}

		logger.close();

		System.out.println("\nFinished!");
	}
}
